package com.cx.volatiledemo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 */
public class Test {


    private  static volatile int sum = 0;

    private static final AtomicInteger integer = new AtomicInteger();
    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(()->{
                for (int j = 0; j < 100; j++) {
                    sum++;
                    integer.incrementAndGet();
                }
            });
            thread.start();
        }

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(sum);
        System.out.println(integer.get());

    }

}
